﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>新增页面</title>
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Source/layui/layui.all.js"></script>
    <script src="~/Source/layui/layui.js"></script>
    <link href="~/Source/layui/css/layui.css" rel="stylesheet" />
    <script>
        $(function () {
            $("#parentSelect").hide();
            $("#divUrl").hide();
            $("#SelectIsParent").change(function () {
                if ($(this).val() == "false") {
                    $("#parentSelect").show();
                    $("#divUrl").show();
                }
            });
            $("#btnSubmit").click(function () {
                $.ajax({
                    url: "/Menus/InsertMenu",
                    type: "post",
                    data: {
                        "Name": $("#txtName").val().trim(),
                        "IsParent": $("#SelectIsParent").val(),
                        "Url": $("#txtUrl").val().trim(),
                        "ParentId": $("#ParentId").val()
                    },
                    success: function (returnData) {
                        if (returnData == 1) {
                            layer.alert("操作成功！");
                        } else {
                            layer.alert("操作失败！");
                        }
                        
                    }, error: function () {

                    }
                });
            });
        })
    </script>
</head>

<body>
  <div style="padding-left:150px; margin-top">
        <form class="am-form">
        <div class="am-g am-margin-top">
            <div class="am-u-sm-2 am-text-right">
                菜单名
            </div>
            <div class="am-u-sm-4">
                <input type="text" class="am-input-sm" id="txtName">
            </div>
            <div class="am-u-sm-6"></div>
        </div>
        <br />
        <div class="am-g am-margin-top">
            <div class="am-u-sm-2 am-text-right">
                是否是父级菜单
            </div>
            <div class="am-u-sm-4 col-end">
                <select id="SelectIsParent">
                    <option value="true">是</option>
                    <option value="false">否</option>
                </select>
            </div>
            <div class="am-u-sm-6"></div>
        </div>

        <br />

        <div class="am-g am-margin-top-sm" id="divUrl">
            <div class="am-u-sm-2 am-text-right">
                URL
            </div>
            <div class="am-u-sm-10">
                <input type="text" class="am-input-sm" id="txtUrl">
            </div>
        </div>

        <br />
        <div class="am-g am-margin-top" id="parentSelect">
            <div class="am-u-sm-2 am-text-right">
                父级菜单
            </div>
            <div class="am-u-sm-4 col-end">
                <select id="ParentId">
                    <option value="0">--请选择--</option>
                    @{
                            
                        var menuList = BLL.MenusManager.QueryList().Where(m => m.IsParent).ToList();
                        if (menuList.Count != 0)
                        {
                            foreach (var item in menuList)
                            {
                        <option value="@item.Id">@item.Name</option>
                            }
                        }
                            
                    }
                </select>
            </div>
            <div class="am-u-sm-6"></div>
        </div>
        <br /> 
        <div class="am-margin">
            <button type="button" id="btnSubmit" class="am-btn am-btn-primary am-btn-xs">提交保存</button>
            <button type="reset" class="am-btn am-btn-primary am-btn-xs">放弃保存</button>
        </div>

    </form>
  </div>
</body>
</html>
